package com.ruoyi.web.controller.system.api.cc;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.framework.interceptor.Authentication;
import com.ruoyi.fsepc.service.IStPlanDetailsService;
import com.ruoyi.system.api.ResponseWithData;
import com.ruoyi.system.api.domain.*;
import com.ruoyi.system.api.mapper.UserMapper;
import com.ruoyi.system.api.service.*;
import com.ruoyi.web.controller.system.task.MultithreadScheduleTask;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;

/**
 * @ClassName PlanDetailsController
 * @Description: 工程师FSE计划详情
 * @Author shihx
 * @Date 2020/2/24
 * @Version V1.0
 **/
@Api(tags="工程师FSE计划详情")
@Controller
@RequestMapping("/api/cc/PlanDetails")
public class PlanDetailsController extends BaseController {

    @Autowired
    private IPlanDetailsService planDetailsService;
    @Autowired
    private IStPlanDetailsService stPlanDetailsService;

    @Autowired
    private IUserService userService;

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private IServiceNoticeService iServiceNoticeService;

    @Autowired
    private CcService ccService;

    private static final Logger log = LoggerFactory.getLogger(PlanDetailsController.class);

    /**
     * 获取员工服务单各种状态的数量接口
     * @methodName: getFseStateCounts
     * @description: TODO
     * @param EnginnerId
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/5 16:26
    **/
    @GetMapping("/getFseStateCounts")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取员工服务单各种状态的数量接口", httpMethod = "GET", notes = "获取员工服务单各种状态的数量接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getFseStateCounts(@RequestParam(value="EnginnerId",required=true) String EnginnerId){
        try {
            return planDetailsService.getFseStateCounts(EnginnerId);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 获取FSE计划安排接口
     * @methodName: getFsePlan
     * @description: TODO
     * @param EnginnerId
     * @param StartTime
     * @param EndTime
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/6 14:45
    **/
    @GetMapping("/getFsePlan")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取FSE计划安排接口", httpMethod = "GET", notes = "获取FSE计划安排接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "开始时间", name = "StartTime", required = true, defaultValue = "2020-03-06 00:00:00", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "结束时间", name = "EndTime", required = true, defaultValue = "2020-03-06 23:59:59", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getFsePlan(
            @RequestParam(value="EnginnerId",required=true) String EnginnerId,
            @RequestParam(value="StartTime",required=true) String StartTime,
            @RequestParam(value="EndTime",required=true) String EndTime
    ){
        try {
            return planDetailsService.getFsePlan(EnginnerId, StartTime, EndTime);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * FSE接受服务接口
     * @methodName: fseAccept
     * @description: TODO
     * @param ServiceNoticeIds
     * @param serviceNos
     * @param EnginnerId
     * @param serviceRole
     * @param StartTime
     * @param workingHours
     * @param EndTime
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/7 8:36
    **/
    @Log(title = "FSE接受服务接口", businessType = BusinessType.UPDATE)
    @GetMapping("/fseAccept")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "FSE接受服务接口", httpMethod = "GET", notes = "FSE接受服务接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID(可能有多个用逗号分隔)", name = "ServiceNoticeIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号（可能有多个用逗号分隔）", name = "serviceNos", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单子表主键ID（可能有多个用逗号分隔）", name = "planIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务角色 1现场服务 2实习", name = "serviceRole", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计上门时间", name = "StartTime", required = true, defaultValue = "2020-03-06 00:00:00", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计工时", name = "workingHours", required = true, defaultValue = "2", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计结束结束时间", name = "EndTime", required = true, defaultValue = "2020-03-06 23:59:59", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "自动签离小时数", name = "signOffAutoHour", required = false, defaultValue = "4", dataType = "Double", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> fseAccept(
            @RequestParam(value="ServiceNoticeIds",required=true) String ServiceNoticeIds,
            @RequestParam(value="serviceNos",required=true) String serviceNos,
            @RequestParam(value="planIds",required=true) String planIds,
            @RequestParam(value="EnginnerId",required=true) String EnginnerId,
            @RequestParam(value="serviceRole",required=true) String serviceRole,
            @RequestParam(value="StartTime",required=true) String StartTime,
            @RequestParam(value="workingHours",required=true) String workingHours,
            @RequestParam(value="EndTime",required=true) String EndTime,
            @RequestParam(value="signOffAutoHour",required=false) Double signOffAutoHour
    ){
        try {
            return planDetailsService.fseAccept(ServiceNoticeIds,serviceNos, planIds, EnginnerId, serviceRole, StartTime,workingHours, EndTime,signOffAutoHour);
        }catch (Exception e){
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * FSE再次上门接口
     * @methodName: updatefseAccept
     * @description: TODO
     * @param ServiceNoticeIds
     * @param serviceNos
     * @param EnginnerId
     * @param serviceRole
     * @param StartTime
     * @param workingHours
     * @param EndTime
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月26日14:11:31
     **/
    @Log(title = "FSE再次上门接口", businessType = BusinessType.UPDATE)
    @GetMapping("/updatefseAccept")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "FSE再次上门接口", httpMethod = "GET", notes = "FSE再次上门接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID(可能有多个用逗号分隔)", name = "ServiceNoticeIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号（可能有多个用逗号分隔）", name = "serviceNos", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单子表主键ID（可能有多个用逗号分隔）", name = "planIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工姓名", name = "enginnerName", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务角色 1现场服务 2实习", name = "serviceRole", required = true, defaultValue = "1", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计上门时间", name = "StartTime", required = true, defaultValue = "2020-03-06 00:00:00", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计工时", name = "workingHours", required = true, defaultValue = "2", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计结束结束时间", name = "EndTime", required = true, defaultValue = "2020-03-06 23:59:59", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "自动签离小时数", name = "signOffAutoHour", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> updatefseAccept(
            @RequestParam(value="ServiceNoticeIds",required=true) String ServiceNoticeIds,
            @RequestParam(value="serviceNos",required=true) String serviceNos,
            @RequestParam(value="planIds",required=true) String planIds,
            @RequestParam(value="EnginnerId",required=true) String EnginnerId,
            @RequestParam(value="enginnerName",required=true) String enginnerName,
            @RequestParam(value="serviceRole",required=true) String serviceRole,
            @RequestParam(value="StartTime",required=true) String StartTime,
            @RequestParam(value="workingHours",required=true) String workingHours,
            @RequestParam(value="EndTime",required=true) String EndTime,
            @RequestParam(value="signOffAutoHour",required=false) Double signOffAutoHour
    ){
        try {
            return planDetailsService.updatefseAccept(ServiceNoticeIds,serviceNos, planIds, EnginnerId, serviceRole, StartTime,workingHours, EndTime, enginnerName,signOffAutoHour);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * FSE拒绝服务接口
     * @methodName: fseRefuse
     * @description: TODO
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/7 9:44
    **/
    @Log(title = "FSE拒绝服务接口", businessType = BusinessType.UPDATE)
    @PostMapping("/fseRefuse")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "FSE拒绝服务接口", httpMethod = "POST", notes = "FSE拒绝服务接口")
//    @ApiImplicitParams({
//            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
//            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
//            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
//            @ApiImplicitParam(value = "拒绝理由", name = "refusalReasons", required = true, defaultValue = "不同意", dataType = "String", paramType = "query"),
//    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> fseRefuse(@RequestBody MyServiceDetails myServiceDetails){
        try {

//            ServiceNotice serviceNotice=new ServiceNotice();
//            serviceNotice.setServiceNo(myServiceDetails.getServiceNo());
//            List<ServiceNotice> serviceNoticeList= iServiceNoticeService.selectServiceNoticeList(serviceNotice);
//            if (serviceNoticeList.size()>0){
//                ServiceNotice serviceNotice1=serviceNoticeList.get(0);
//                if(serviceNotice1.getTeamleaderId()!=null){
//                    iServiceNoticeService.TransferTL2( myServiceDetails.getFseId(), myServiceDetails.getServiceNo(),serviceNotice1.getTeamleaderId());
//                 //   return planDetailsService.fseRefuse(myServiceDetails.getServiceNoticeId()+"",myServiceDetails.getServiceNo(), myServiceDetails.getFseId(), myServiceDetails.getRefusalReasons(), myServiceDetails.getPlanId(), myServiceDetails.getFseName());
//
//                }else{
//                    User user = new User();
//                    user.setEnginnerId(Long.parseLong(myServiceDetails.getFseId()));
//                    List<User> users = userMapper.selectUserList(user);
//                    if(users.size()>0){
//                        User usertemp=users.get(0);
//                        iServiceNoticeService.TransferTL2( myServiceDetails.getFseId(), myServiceDetails.getServiceNo(),usertemp.getTeamleaderId());
//                    }
//                 //   return planDetailsService.fseRefuse(myServiceDetails.getServiceNoticeId()+"",myServiceDetails.getServiceNo(), myServiceDetails.getFseId(), myServiceDetails.getRefusalReasons(), myServiceDetails.getPlanId(), myServiceDetails.getFseName());
//
//                }
//            }

            // 拒绝cc通知开始s'd
            String ccflag=ccService.refuseServicehandle(myServiceDetails.getFseId(),myServiceDetails.getServiceNo());
            if(!"1".equals(ccflag)){
                return new ResponseWithData().error().msg("CC接口异常").code(201);
            }
            //拒绝cc通知结束

            return planDetailsService.fseRefuse(myServiceDetails.getServiceNoticeId()+"",myServiceDetails.getServiceNo(), myServiceDetails.getFseId(), myServiceDetails.getRefusalReasons(), myServiceDetails.getPlanId(), myServiceDetails.getFseName());
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * FSE签到服务接口
     * @methodName: fseSign
     * @description: TODO
     * @param ServiceNoticeIds
     * @param serviceNos
     * @param EnginnerId
     * @param longitude
     * @param latitude
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 9:18
    **/
    @Log(title = "FSE签到服务接口", businessType = BusinessType.UPDATE)
    @GetMapping("/fseSign")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "FSE签到服务接口", httpMethod = "GET", notes = "FSE签到服务接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID(可能有多个用逗号分隔)", name = "ServiceNoticeIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号（可能有多个用逗号分隔）", name = "serviceNos", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务单子表主键ID（可能有多个用逗号分隔）", name = "planIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "经度", name = "longitude", required = true, defaultValue = "125.222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "纬度", name = "latitude", required = true, defaultValue = "43.2222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "关联服务号", name = "relServiceNo", required = true, defaultValue = "43.2222", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> fseSign(
            @RequestParam(value="ServiceNoticeIds",required=true) String ServiceNoticeIds,
            @RequestParam(value="serviceNos",required=true) String serviceNos,
            @RequestParam(value="planIds",required=true) String planIds,
            @RequestParam(value="EnginnerId",required=true) String EnginnerId,
            @RequestParam(value="longitude",required=true) String longitude,
            @RequestParam(value="latitude",required=true) String latitude,
            @RequestParam(value="relServiceNo",required=true) String relServiceNo
    ){
        try {
            return planDetailsService.fseSign(ServiceNoticeIds,serviceNos,planIds, EnginnerId, longitude, latitude,relServiceNo);
        }catch (Exception e){
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * FSE签离服务接口
     * @methodName: fseSignOff
     * @description: TODO
     * @param ServiceNoticeId
     * @param serviceNo
     * @param EnginnerId
     * @param longitude
     * @param latitude
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 10:46
    **/
    @Log(title = "FSE签离服务接口", businessType = BusinessType.UPDATE)
    @GetMapping("/fseSignOff")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "FSE签离服务接口", httpMethod = "GET", notes = "FSE签离服务接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNos", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = true, defaultValue = "中国", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到时间", name = "signInTime", required = true, defaultValue = "2020-111-12 12:12:12", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "经度", name = "longitude", required = true, defaultValue = "125.222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "纬度", name = "latitude", required = true, defaultValue = "43.2222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态", name = "state", required = true, defaultValue = "4", dataType = "String", paramType = "query"),

    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> fseSignOff(
            @RequestParam(value="ServiceNoticeId",required=true) String ServiceNoticeId,
            @RequestParam(value="serviceNo",required=true) String serviceNo,
            @RequestParam(value="EnginnerId",required=true) String EnginnerId,
            @RequestParam(value="customerName",required=true) String customerName,
            @RequestParam(value="signInTime",required=true) String signInTime,
            @RequestParam(value="longitude",required=true) String longitude,
            @RequestParam(value="latitude",required=true) String latitude,
            @RequestParam(value="state",required=true) String state
    ){
        try {
            return planDetailsService.fseSignOff(ServiceNoticeId,serviceNo, EnginnerId, customerName, signInTime, longitude, latitude,state);

        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * FSE签离服务预计再次上门接口
     * @methodName: fseSignOff
     * @description: TODO
     * @param ServiceNoticeId
     * @param
     * @param EnginnerId
     * @param longitude
     * @param latitude
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: sjy
     * @date: 2020年3月26日16:37:56
     **/
    @Log(title = "FSE签离服务预计再次上门接口", businessType = BusinessType.INSERT)
    @GetMapping("/fseSignOffAgain")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "FSE签离服务预计再次上门接口", httpMethod = "GET", notes = "FSE签离服务预计再次上门接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeIds", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNos", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "EnginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "客户名称", name = "customerName", required = true, defaultValue = "中国", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "签到时间", name = "signInTime", required = true, defaultValue = "2020-111-12 12:12:12", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "经度", name = "longitude", required = true, defaultValue = "125.222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "纬度", name = "latitude", required = true, defaultValue = "43.2222", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "状态", name = "state", required = true, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计上门时间", name = "estimatedVisitingTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计工时", name = "estimatedWorkingHours", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计离开时间", name = "estimatedDepartureTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "自动签离小时数", name = "signOffAutoHour", required = false, defaultValue = "4", dataType = "Double", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> fseSignOffAgain(
            @RequestParam(value="ServiceNoticeId",required=true) String ServiceNoticeId,
            @RequestParam(value="EnginnerId",required=true) String EnginnerId,
            @RequestParam(value="customerName",required=true) String customerName,
            @RequestParam(value="signInTime",required=true) String signInTime,
            @RequestParam(value="longitude",required=true) String longitude,
            @RequestParam(value="latitude",required=true) String latitude,
            @RequestParam(value="state",required=true) String state,
            @RequestParam(value="estimatedVisitingTime",required=false) String estimatedVisitingTime,
            @RequestParam(value="estimatedWorkingHours",required=false) String estimatedWorkingHours,
            @RequestParam(value="estimatedDepartureTime",required=false) String estimatedDepartureTime,
            @RequestParam(value="signOffAutoHour",required=false) Double signOffAutoHour
    ){
        try {
            return planDetailsService.fseSignOffAgain(ServiceNoticeId, EnginnerId, customerName,
                    signInTime, longitude, latitude,state,estimatedVisitingTime,estimatedWorkingHours,estimatedDepartureTime,signOffAutoHour);
        }catch (Exception e){
            e.printStackTrace();
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 查询服务详情
     * @methodName: fseSignOff
     * @description: TODO
     * @param ServiceNoticeId
     * @param fseId
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 10:46
     **/
    @GetMapping("/getPlanDetails")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询服务详情", httpMethod = "GET", notes = "查询服务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "ServiceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "fseId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getPlanDetails(
            @RequestParam(value="ServiceNoticeId",required=true) String ServiceNoticeId,
            @RequestParam(value="fseId",required=true) String fseId){
        try {
            PlanDetails planDetails = new PlanDetails();
            planDetails.setServiceNoticeId(Long.parseLong(ServiceNoticeId));
            planDetails.setFseId(fseId);
            planDetails =  planDetailsService.getPlanDetails(planDetails);
            return new ResponseWithData<>().success(planDetails).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }


    /**
     * 查询服务详情
     * @methodName: fseSignOff
     * @description: TODO
     * @param id
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020/3/9 10:46
     **/
    @GetMapping("/getDetailsById")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "查询服务详情", httpMethod = "GET", notes = "查询服务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "主键ID", name = "id", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    public ResponseWithData<?> getDetailsById(
            @RequestParam(value="id",required=true) String id){
        try {
            PlanDetails planDetails =  planDetailsService.selectStPlanDetailsById(Long.parseLong(id));
            return new ResponseWithData<>().success(planDetails).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 自动签离的服务单改为已完成
     * @methodName: signOffAutoState
     * @description: TODO
     * @param serviceNoticeId
     * @param enginnerId
     * @param planId
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-08 16:20
    **/
    @Log(title = "自动签离的服务单改为已完成", businessType = BusinessType.UPDATE)
    @GetMapping("/signOffAutoState")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "自动签离的服务单改为已完成", httpMethod = "GET", notes = "自动签离的服务单改为已完成")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "serviceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "计划ID", name = "planId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> signOffAutoState(
            @RequestParam(value="serviceNoticeId",required=true) String serviceNoticeId,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="planId",required=true) String planId
    ){
        try {
            return planDetailsService.signOffAutoState(serviceNoticeId, enginnerId, planId);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * FSE自动签离服务预计再次上门接口
     * @methodName: fseSignOffAutoAgain
     * @description: TODO
     * @param serviceNoticeId
     * @param serviceNo
     * @param enginnerId
     * @param estimatedVisitingTime
     * @param estimatedWorkingHours
     * @param estimatedDepartureTime
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-08 19:15
    **/
    @Log(title = "FSE自动签离服务预计再次上门接口", businessType = BusinessType.UPDATE)
    @GetMapping("/fseSignOffAutoAgain")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "FSE自动签离服务预计再次上门接口", httpMethod = "GET", notes = "FSE自动签离服务预计再次上门接口")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单主键ID", name = "serviceNoticeId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "服务号", name = "serviceNo", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "计划ID", name = "planId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计上门时间", name = "estimatedVisitingTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计工时", name = "estimatedWorkingHours", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计离开时间", name = "estimatedDepartureTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "自动签离小时数", name = "signOffAutoHour", required = false, defaultValue = "4", dataType = "Double", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> fseSignOffAutoAgain(
            @RequestParam(value="serviceNoticeId",required=true) String serviceNoticeId,
            @RequestParam(value="serviceNo",required=true) String serviceNo,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="planId",required=true) String planId,
            @RequestParam(value="estimatedVisitingTime",required=false) String estimatedVisitingTime,
            @RequestParam(value="estimatedWorkingHours",required=false) String estimatedWorkingHours,
            @RequestParam(value="estimatedDepartureTime",required=false) String estimatedDepartureTime,
            @RequestParam(value="signOffAutoHour",required=false) Double signOffAutoHour
    ){
        try {
            return planDetailsService.fseSignOffAutoAgain(serviceNoticeId, serviceNo, enginnerId, planId, estimatedVisitingTime, estimatedWorkingHours, estimatedDepartureTime,signOffAutoHour);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * TL查询下级FSE未填写日志的数据
     * @methodName: fseFillLogCount
     * @description: TODO
     * @param enginnerId
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-09 17:14
    **/
    @GetMapping("/fseFillLogCount")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "TL查询下级FSE未填写日志的数据", httpMethod = "GET", notes = "TL查询下级FSE未填写日志的数据")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> fseFillLogCount(
            @RequestParam(value="enginnerId",required=true) String enginnerId
    ){
        try {
            return planDetailsService.fseFillLogCount(enginnerId);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping("/updateEstimatedVisitingTime")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "TL查询下级FSE未填写日志的数据", httpMethod = "GET", notes = "TL查询下级FSE未填写日志的数据")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "计划ID", name = "planId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计上门时间", name = "estimatedVisitingTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计工时", name = "estimatedWorkingHours", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计离开时间", name = "estimatedDepartureTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "自动签离小时数", name = "signOffAutoHour", required = false, defaultValue = "4", dataType = "Double", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> updateEstimatedVisitingTime(
            @RequestParam(value="planId",required=true) String planId,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="estimatedVisitingTime",required=false) String estimatedVisitingTime,
            @RequestParam(value="estimatedWorkingHours",required=false) String estimatedWorkingHours,
            @RequestParam(value="estimatedDepartureTime",required=false) String estimatedDepartureTime,
            @RequestParam(value="signOffAutoHour",required=false) Double signOffAutoHour
    ){
        try {
            return planDetailsService.updateEstimatedVisitingTime(planId, enginnerId, estimatedVisitingTime, estimatedWorkingHours, estimatedDepartureTime,signOffAutoHour);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 团队查询人员计划任务详情
     * @methodName: selectPlanDetailsList
     * @description: TODO
     * @param serviceNo
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-23 13:09
    **/
    @GetMapping("/selectPlanDetailsList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "团队查询人员计划任务详情", httpMethod = "GET", notes = "团队查询人员计划任务详情")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单号", name = "serviceNo", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> selectPlanDetailsList(
            @RequestParam(value="serviceNo",required=true) String serviceNo
    ){
        try {
            PlanDetails planDetails = new PlanDetails();
            planDetails.setServiceNo(serviceNo);
            planDetails.setDelFlag("0");
            List<PlanDetails> detailsList = planDetailsService.selectStPlanDetailsList(planDetails);
            return new ResponseWithData<>().success(detailsList).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    /**
     * 有下次预计上门查询最后一次签离的ID
     * @methodName: selectOldPlanDetailId
     * @description: TODO
     * @param serviceNo
     * @param enginnerId
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-25 16:37
    **/
    @GetMapping("/selectOldPlanDetailId")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "有下次预计上门查询最后一次签离的ID", httpMethod = "GET", notes = "有下次预计上门查询最后一次签离的ID")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单号", name = "serviceNo", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> selectOldPlanDetailId(
            @RequestParam(value="serviceNo",required=true) String serviceNo,
            @RequestParam(value="enginnerId",required=true) String enginnerId
    ){
        try {
            PlanDetails planDetails = new PlanDetails();
            planDetails.setServiceNo(serviceNo);
            planDetails.setFseId(enginnerId);
            planDetails.setState("3");
            PlanDetails detailsList = planDetailsService.selectOldPlanDetailId(planDetails);
            return new ResponseWithData<>().success(detailsList).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
    /**
     * 获取上次planId
     * @methodName: selectAllOldPlanDetailId
     * @description: TODO
     * @param
     * @param enginnerId
     * @return: com.ruoyi.system.api.ResponseWithData<?>
     * @author: shihx
     * @date: 2020-04-25 16:37
     **/
    @GetMapping("/selectAllOldPlanDetailId")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "有下次预计上门查询最后一次签离的ID", httpMethod = "GET", notes = "有下次预计上门查询最后一次签离的ID")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务单号", name = "serviceNo", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "state", required = false, defaultValue = "4", dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> selectAllOldPlanDetailId(
            @RequestParam(value="serviceNoticeId",required=true) Long serviceNoticeId,
            @RequestParam(value="enginnerId",required=true) String enginnerId

    ){
        try {
            PlanDetails planDetails = new PlanDetails();
            planDetails.setServiceNoticeId(serviceNoticeId);
            planDetails.setFseId(enginnerId);
            PlanDetails detailsList = planDetailsService.selectAllOldPlanDetailId(planDetails);
            return new ResponseWithData<>().success(detailsList).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping("/checkPlanDetailsList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "验证时间是否冲突", httpMethod = "GET", notes = "验证时间是否冲突")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "计划ID", name = "planId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计上门时间", name = "estimatedVisitingTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "预计离开时间", name = "estimatedDepartureTime", required = false, defaultValue = "4", dataType = "String", paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> checkPlanDetailsList(
            @RequestParam(value="planId",required=true) String planId,
            @RequestParam(value="enginnerId",required=true) String enginnerId,
            @RequestParam(value="estimatedVisitingTime",required=false) String estimatedVisitingTime,
            @RequestParam(value="estimatedDepartureTime",required=false) String estimatedDepartureTime
    ){
        try {
            return planDetailsService.checkPlanDetailsList(planId, enginnerId, estimatedVisitingTime, estimatedDepartureTime);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }

    @GetMapping("/checkPlanDetailsVisitList")
    @ResponseBody
    @Authentication(tokenRequired = true, signRequired = true)
    @ApiOperation(value = "获取上门记录", httpMethod = "GET", notes = "获取上门记录")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "服务编号", name = "serviceNo", required = true, defaultValue = "10009", dataType = "String", paramType = "query"),
            @ApiImplicitParam(value = "员工ID", name = "enginnerId", required = true, defaultValue = "10009", dataType = "String", paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code = 500, message = "code 为 500 系统异常"),
            @ApiResponse(code = 200, message = "code 为 200 成功")
    })
    @Transactional(rollbackFor = Exception.class)
    public ResponseWithData<?> checkPlanDetailsVisitList(
            @RequestParam(value="serviceNo",required=true) String serviceNo, @RequestParam(value="enginnerId",required=true) String enginnerId
    ){
        try {
            List<Map<String,String>> planList = stPlanDetailsService.checkPlanDetailsVisitList(serviceNo,enginnerId);
            return new ResponseWithData<>().success(planList).msg("查询成功").code(200);
        }catch (Exception e){
            log.error("程序异常", e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return new ResponseWithData().error().msg("系统异常").code(500);
        }
    }
}
